/**
 * All Rights Reserved , Copyright (C) 2023 , 青岛鼎信通讯股份有限公司
 *
 *CbbPmTaskProgressController
 * WBS任务进度记录表
 *
 * 修改纪录
 * 2023-06-25 版本：1.0 wuyuyang 创建。
 * @version 版本：1.0
 * @author 作者：wuyuyang
 * 创建日期：2023-06-25
 */

package com.topscomm.mis.cbb.pm.controller;

import java.util.Map;

import com.topscomm.basic.exception.MessageException;
import com.topscomm.basic.exception.UnauthorizedException;
import com.topscomm.cbo.pojo.CboSystemErrorLogEntity;
import com.topscomm.mis.cbb.pm.api.ITaskProgressService;
import com.topscomm.mis.cbb.pm.base.service.ICbbPmTaskService;
import com.topscomm.pub.util.BaseUtil;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.vo.Page;
import com.topscomm.tap.constant.TapHttpErrorCode;
import com.topscomm.tap.constant.TapHttpStatus;
import com.topscomm.tap.util.ErrorLogUtil;
import org.apache.poi.hssf.record.DVALRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.topscomm.mis.cbb.pm.controller.auto.CbbPmTaskProgressControllerAuto;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: wuyuyang
 * @date: 2023-06-25
 * @description:WBS任务进度记录表Controller
 * @modify:
 */
@Validated
@RestController
@RequestMapping("cbb/cbbPmTaskProgress")
public class CbbPmTaskProgressController extends CbbPmTaskProgressControllerAuto  {
    @Autowired
	private ITaskProgressService taskProgressService;
	/**
	 * @author: wuyuyang
	 * @date: 2023-06-25
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		if (paraMap.containsKey("qry_taskcode")) {
			String value = paraMap.get("qry_taskcode").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and taskcode = '{0}' ", value);
		}
		if (paraMap.containsKey("qry_round")) {
			String value = paraMap.get("qry_round").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and round = {0} ", value);
			}
		}
		return sql.toString();
	}

//	/**
//	 * @author: wuyuyang
//	 * @date: 2023-06-25
//	 * @param paraMap
//	 * @return
//	 * @description:转换出查询SQL语句
//	 * @modify:
//	 */
//	@GetMapping(value = "/refList")
//	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
//		return super.refList(paraMap);
//	}


	@PostMapping(value = "/insert")
	public ResponseResult<Object> insert(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			Map<String, Object> resMap = taskProgressService.insert(paraMap);
			return ResponseResult.ok(resMap);
		} catch(Exception ex) {
			return handleControllerException(ex);
		}
	}


	@PutMapping(value = "/update")
	public ResponseResult<Object> update(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			taskProgressService.update(paraMap);
			return ResponseResult.ok("修改成功");
		} catch(Exception ex) {
			return handleControllerException(ex);
		}
	}


	@DeleteMapping(value = "/delete")
	public ResponseResult<Object> delete(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			BaseUtil.decodeSecureMap(paraMap);
			taskProgressService.delete(paraMap);
			return ResponseResult.ok("删除成功");
		} catch(Exception ex) {
			return handleControllerException(ex);
		}
	}


	@GetMapping(value = "/load")
	public ResponseResult<Object> load(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			BaseUtil.decodeSecureMap(paraMap);
			Map<String, Object> dataMap = taskProgressService.load(paraMap);
			return ResponseResult.ok(dataMap);
		} catch(Exception ex) {
			return handleControllerException(ex);
		}
	}



	@GetMapping(value = "/list")
	public ResponseResult<Object> list(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			BaseUtil.decodeSecureMap(paraMap);
			String sqlWhere = this.spellListSql(paraMap);
			Page page = taskProgressService.list(paraMap, sqlWhere);
			return ResponseResult.ok(page);
		} catch(Exception ex) {
			return handleControllerException(ex);
		}
	}

    /**
     * @Description:    我的任务特殊筛选方法、勿动
     * @Author:         wuyuyang
     * @Return:         java.lang.String
     * @exception:
     * @Date:           28/7/2023 上午11:23
     * @Version:        1.0
     **/
	public String spellListSqlforindex(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_wbscode")) {
			String value = paraMap.get("qry_wbscode").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and wbscode = '{0}' ", value);
			}
		}
		if (paraMap.containsKey("qry_responsibleusercode")) {
			String value = paraMap.get("qry_responsibleusercode").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and responsibleusercode = '{0}' ", value);
			}
		}
		if (paraMap.containsKey("qry_projectuucode")) {
			String value = paraMap.get("qry_projectuucode").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and projectuucode = '{0}' ", value);
			}
		}
		if (paraMap.containsKey("qry_projectcode")) {
			String value = paraMap.get("qry_projectcode").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and projectcode = '{0}' ", value);
			}
		}
		if (paraMap.containsKey("qry_status")) {
			String value = paraMap.get("qry_status").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and status in ({0}) ", value);
			}
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and a.code like '%{0}%' ", value);
			}
		}
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and a.name like '%{0}%' ", value);
			}
		}
		if (paraMap.containsKey("qry_deliverystatus")) {
			String value = paraMap.get("qry_deliverystatus").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and deliverystatus = {0} ", value);
			}
		}
		return sql.toString();
	}
	/**
	 * @Description:    我的任务特殊查询方法、勿动
	 * @Author:         wuyuyang
	 * @Return:         com.topscomm.pub.vo.ResponseResult<java.lang.Object>
	 * @exception:
	 * @Date:           14/7/2023 上午10:39
	 * @Version:        1.0
	 **/
	@GetMapping(value = "/listforindex")
	public ResponseResult<Object> listforindex(@RequestParam(required = false) Map<String, Object> paraMap) {
		BaseUtil.decodeSecureMap(paraMap);
		String sqlWhere = this.spellListSqlforindex(paraMap);
		Page page = taskProgressService.listforMytask(paraMap, sqlWhere);
		return ResponseResult.ok(page);
	}

	/**
	 * @Description:    cbb判断对应系统WBS负责人
	 * @Author:         wuyuyang
	 * @Return:         com.topscomm.pub.vo.ResponseResult<java.lang.Object>
	 * @exception:
	 * @Date:           28/7/2023 上午11:46
	 * @Version:        1.0
	 **/
	@GetMapping(value = "/checkSysCbbAdmin")
	public ResponseResult<Object> checkSysCbbAdmin(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			BaseUtil.decodeSecureMap(paraMap);
			boolean result = taskProgressService.checkSysCbbAdmin(paraMap);
			return ResponseResult.ok(result);
		} catch(Exception ex) {
			return handleControllerException(ex);
		}
	}
}

